var HyperbahnClient = require('tchannel/hyperbahn/');
var rootChannel = require('tchannel');

var hyperbahnClient = HyperbahnClient({
    tchannel: rootChannel,
    serviceName: 'keyvalue-client',
    hostPortList: ['127.0.0.1:4040'],
    hardFail: true
});

var keyChan = hyperbahnClient.getClientChannel({
    serviceName: 'keyvalue'
});

console.log(keyChan);

var keyThrift = rootChannel.TChannelAsThrift({
    entryPoint: path.join(__dirname, 'thrift/keyvalue.thrift'),
    channel: keyChan
});

keyThrift.request({
    serviceName: 'keyvalue',
    timeout: 10000
}).send('KeyValue::put_v1', null, {
    key: 'hello',
    value: 'world'
}, function onResponse(err, resp) {
    if (err) {
        return logger.error('got an error', {
            error: err
        });
    }

    logger.info('got result', {
        ok: resp.ok,
        body: resp.body
    });
});